class Solution {
public:
    bool isMatch(const char *s, const char *p) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
		if (s == NULL || p == NULL) {
			return false;
		}
		if (*p == 0) {
			return *s == 0;
		}

		if (*(p + 1) != '*') {
			return (*p == *s || (*p == '.' && *s != 0)) && IsMatch(s + 1, p + 1);
		} else {
			if (IsMatch(s, p + 2)) {
				return true;
			}
			int index = 0;
			while ( (*p == '.' && *(s + index) != 0) ||
					(*p == *(s + index)) ) {
				if (IsMatch(s + index + 1, p + 2)) {
					return true;
				}
			}
		}
		return false;

    }
};



